﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IronOne.SalesOne.BusinessObjects;
using Facade;


using System.Data;

namespace IronOne.SalesOne.SalesOneWeb
{
    public partial class ManageBranches : System.Web.UI.Page
    {
        public List<Branch> branchList;
        public List<Branch> branchList123; 

        protected void Page_Load(object sender, EventArgs e)
        {
            
            lblHeader.Text = "Manage Branch";
            if (!IsPostBack)
            {
                DataSource();
               
                DataSet ds = new DataSet();
                DataTable Dt = new DataTable();
                Dt.Columns.Add("Branch ID");
                Dt.Columns.Add("Branch Name");
                Dt.Columns.Add("Effective From");
                Dt.Columns.Add("Effective To");

                for (int x = 0; x <branchList.Count ; x++)
                {
                    Dt.Rows.Add();
                    Dt.Rows[x][0] = branchList[x].BranchId;
                    Dt.Rows[x][1] = branchList[x].BranchName;
                    Dt.Rows[x][2] = branchList[x].EffectiveFrom ;
                    Dt.Rows[x][3] = branchList[x].EffectiveTo ;

                }
                ds.Tables.Add(Dt);
                UCGrid1.SetDataSource(ds);
               
            }
        }
        
             private List<Branch> DataSource()
        {
            DataTable brTable = new DataTable();
            StructureFacade bf = new StructureFacade();

            branchList = bf.GetBranches("BranchId ASC");
            
            //branchList=bf.GetBranchesFromGroup()
            return branchList;
                
        }


             public void DataSource123(string s)
             {
                 if (!IsPostBack)
                 {
                     string gpName = s;
                     getBranches(gpName);
                     
                     DataSet ds = new DataSet();
                     DataTable Dt = new DataTable();
                     Dt.Columns.Add("Branch ID");
                     Dt.Columns.Add("Branch Name");
                     Dt.Columns.Add("Effective From");
                     Dt.Columns.Add("Effective To");

                     for (int x = 0; x < branchList123.Count; x++)
                     {
                         Dt.Rows.Add();
                         Dt.Rows[x][0] = branchList123[x].BranchId;
                         Dt.Rows[x][1] = branchList123[x].BranchName;
                         Dt.Rows[x][2] = branchList123[x].EffectiveFrom;
                         Dt.Rows[x][3] = branchList123[x].EffectiveTo;

                     }
                     ds.Tables.Add(Dt);
                     //IronOne.SalesOne.SalesOneWeb.UserControls.UCUserGrid uc1 = new IronOne.SalesOne.SalesOneWeb.UserControls.UCUserGrid();
                     //UCGrid1.SetDataSource(branchList123);
                     UCGrid1.SetDataSource(ds);
                    
                     //UCGrid1.SetDataSource(ds);
                 }

             }

             public List<Branch> getBranches(string s1)
             {
                 string gpname2 = s1;
                 StructureFacade bf1 = new StructureFacade();
                // branchList123 = bf1.GetBranchesFromGroup(gpname2);
                 return branchList123;
             }
        /*
             public List<Branch> getUserGrid(List<Branch> list)
             {
                 return UCGrid1.SetDataSource(list);
             }
         * 
         * 
         * */

           
    }
    }

